﻿// WebZHX.Infrastructure/Data/Configurations/FlourBatchOutNewConfiguration.cs
using Core.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace WebZHX.Infrastructure.Data.Configurations
{
    /// <summary>
    /// 面粉出库批次配置
    /// </summary>
    public class FlourBatchOutNewConfiguration : IEntityTypeConfiguration<FlourBatchOutNew>
    {
        public void Configure(EntityTypeBuilder<FlourBatchOutNew> builder)
        {
            // 表名
            builder.ToTable("FlourBatchOut_new");

            // 主键
            builder.HasKey(f => f.Id);

            // 属性配置
            builder.Property(f => f.DrawnWeight)
                .IsRequired()
                .HasColumnType("decimal(18,2)"); // 根据实际数据库精度调整

            builder.Property(f => f.TotalWeight)
                .IsRequired()
                .HasColumnType("decimal(18,2)");

            builder.Property(f => f.RemainingWeight)
                .IsRequired()
                .HasColumnType("decimal(18,2)");

            builder.Property(f => f.BatchNumber)
                .HasMaxLength(50);

            builder.Property(f => f.Operator)
                .HasMaxLength(50);

            builder.Property(f => f.Remark)
                .HasMaxLength(500);

            builder.Property(f => f.OutTime)
                .IsRequired();

            // 索引配置（根据查询需求添加）
            builder.HasIndex(f => f.BatchNumber);
            builder.HasIndex(f => f.OutTime);

            // 默认值配置

            builder.Property(f => f.IsDeleted)
                .HasDefaultValue(false);
        }
    }
}